﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ManageTicket.Ticket
{
    public partial class frmQuickSearchVoucher : Form
    {
        public frmQuickSearchVoucher(ArrayList arr)
        {
            InitializeComponent();
            arrSearchResult = arr;
        }

        ArrayList arrSearchResult;
        public ArrayList arrResult;
        Business.Customer boCustomer = new Business.Customer();

        private void frmQuickSearchVoucher_Load(object sender, EventArgs e)
        {
            lvwVoucher.Items.Clear();
            ListViewItem item;
            DataObjects.Customer oCus;

            foreach (DataObjects.Voucher oVou in arrSearchResult)
            {
                item = new ListViewItem();
                item.Text = oVou.VoucherNo;
                item.SubItems.Add(oVou.CustomerId);
                oCus = boCustomer.GetObjectByPK(oVou.CustomerId);
                if (oCus != null)
                    item.SubItems.Add(oCus.CustomerName);
                else
                    item.SubItems.Add("");
                item.SubItems.Add(oVou.DateOfVoucher.Value.ToString("dd/MM/yyyy hh:mm tt"));
                lvwVoucher.Items.Add(item);

                lblCount.Text = "Tổng: " + lvwVoucher.Items.Count.ToString();
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            arrResult = new ArrayList();
            DataObjects.Voucher oVou;
            foreach (ListViewItem item in lvwVoucher.CheckedItems)
            {
                oVou = new DataObjects.Voucher();
                oVou.VoucherNo = item.Text;
                oVou.CustomerId = item.SubItems[1].Text;
                //oVou.DateOfVoucher = Convert.ToDateTime(item.SubItems[3].Text);

                arrResult.Add(oVou);
            }
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            arrResult = new ArrayList();
            this.Close();
        }
    }
}
